#ifndef FILELISTCONTEXTMENU_H
#define FILELISTCONTEXTMENU_H

#include <QObject>
#include <QMenu>
#include <QAction>
#include <QList>
#include <QString>

/**
 * FileListContextMenu - Replace Conditional with Polymorphism
 *
 * Martin Fowler重构模式应用：
 * - 统一所有右键菜单为简洁的一级菜单
 * - 消除复杂的条件逻辑
 * - 提供一致的用户体验
 */
class FileListContextMenu : public QObject
{
    Q_OBJECT

public:
    explicit FileListContextMenu(QObject* parent = nullptr);
    ~FileListContextMenu() = default;

    // === 统一菜单创建 ===
    QMenu* createUnifiedMenu(const QList<int>& selectedIndices, int contextIndex);

signals:
    // 统一的操作信号
    void removeFilesRequested(const QList<int>& indices);
    void exportSingleRequested(int index);
    void exportMultipleRequested(const QList<int>& indices);
    void exportMergedRequested(const QList<int>& indices);
    void moveToTopRequested(const QList<int>& indices);
    void moveToBottomRequested(const QList<int>& indices);
    void selectAllRequested();
    void clearSelectionRequested();

    // 排序操作信号
    void naturalSortRequested(const QList<int>& indices);
    void reverseSortRequested(const QList<int>& indices);

private slots:
    // 内部槽函数处理
    void handleRemoveFiles();
    void handleExportSingle();
    void handleExportMultiple();
    void handleExportMerged();
    void handleMoveToTop();
    void handleMoveToBottom();
    void handleSelectAll();
    void handleClearSelection();

    // 排序操作槽函数
    void handleNaturalSort();
    void handleReverseSort();

private:
    // === 菜单创建方法 ===
    void addFileOperations(QMenu* menu, const QList<int>& selectedIndices);
    void addExportOperations(QMenu* menu, const QList<int>& selectedIndices);
    void addArrangeOperations(QMenu* menu, const QList<int>& selectedIndices);
    void addSortOperations(QMenu* menu, const QList<int>& selectedIndices);
    void addSelectionOperations(QMenu* menu);

    // === 状态管理 ===
    QList<int> m_currentSelectedIndices;
    int m_currentContextIndex;

    // === 符号常量 ===
    static const int SINGLE_SELECTION = 1;
    static const int MAX_DISPLAY_COUNT = 10;
};

#endif // FILELISTCONTEXTMENU_H